from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-23 14:02:09.985131
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 23, Mar, 2022
Time: 14:02:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.6510
Nobs: 604.000 HQIC: -49.0518
Log likelihood: 7267.41 FPE: 3.85645e-22
AIC: -49.3072 Det(Omega_mle): 3.32663e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350401 0.066479 5.271 0.000
L1.Burgenland 0.107559 0.040479 2.657 0.008
L1.Kärnten -0.110622 0.021173 -5.225 0.000
L1.Niederösterreich 0.192418 0.084614 2.274 0.023
L1.Oberösterreich 0.120778 0.083429 1.448 0.148
L1.Salzburg 0.258985 0.042939 6.031 0.000
L1.Steiermark 0.036727 0.056690 0.648 0.517
L1.Tirol 0.102476 0.045736 2.241 0.025
L1.Vorarlberg -0.067950 0.040380 -1.683 0.092
L1.Wien 0.016563 0.074256 0.223 0.823
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054248 0.142866 0.380 0.704
L1.Burgenland -0.038119 0.086991 -0.438 0.661
L1.Kärnten 0.042001 0.045501 0.923 0.356
L1.Niederösterreich -0.202769 0.181837 -1.115 0.265
L1.Oberösterreich 0.455491 0.179292 2.541 0.011
L1.Salzburg 0.282873 0.092277 3.065 0.002
L1.Steiermark 0.112389 0.121829 0.923 0.356
L1.Tirol 0.305965 0.098288 3.113 0.002
L1.Vorarlberg 0.026787 0.086777 0.309 0.758
L1.Wien -0.029996 0.159578 -0.188 0.851
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198204 0.034002 5.829 0.000
L1.Burgenland 0.089173 0.020704 4.307 0.000
L1.Kärnten -0.007165 0.010829 -0.662 0.508
L1.Niederösterreich 0.242255 0.043277 5.598 0.000
L1.Oberösterreich 0.160017 0.042672 3.750 0.000
L1.Salzburg 0.040097 0.021962 1.826 0.068
L1.Steiermark 0.026946 0.028995 0.929 0.353
L1.Tirol 0.081933 0.023393 3.502 0.000
L1.Vorarlberg 0.054249 0.020653 2.627 0.009
L1.Wien 0.116391 0.037980 3.065 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118648 0.033974 3.492 0.000
L1.Burgenland 0.043143 0.020687 2.086 0.037
L1.Kärnten -0.012940 0.010820 -1.196 0.232
L1.Niederösterreich 0.171764 0.043242 3.972 0.000
L1.Oberösterreich 0.335472 0.042636 7.868 0.000
L1.Salzburg 0.099791 0.021944 4.548 0.000
L1.Steiermark 0.112076 0.028971 3.869 0.000
L1.Tirol 0.089264 0.023373 3.819 0.000
L1.Vorarlberg 0.060620 0.020636 2.938 0.003
L1.Wien -0.018042 0.037948 -0.475 0.634
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126107 0.063764 1.978 0.048
L1.Burgenland -0.044618 0.038826 -1.149 0.250
L1.Kärnten -0.045317 0.020308 -2.231 0.026
L1.Niederösterreich 0.136503 0.081158 1.682 0.093
L1.Oberösterreich 0.161836 0.080022 2.022 0.043
L1.Salzburg 0.284516 0.041185 6.908 0.000
L1.Steiermark 0.057912 0.054375 1.065 0.287
L1.Tirol 0.158086 0.043868 3.604 0.000
L1.Vorarlberg 0.097650 0.038731 2.521 0.012
L1.Wien 0.070331 0.071223 0.987 0.323
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076777 0.049761 1.543 0.123
L1.Burgenland 0.025387 0.030299 0.838 0.402
L1.Kärnten 0.053175 0.015848 3.355 0.001
L1.Niederösterreich 0.190340 0.063335 3.005 0.003
L1.Oberösterreich 0.331250 0.062448 5.304 0.000
L1.Salzburg 0.035106 0.032141 1.092 0.275
L1.Steiermark 0.008113 0.042434 0.191 0.848
L1.Tirol 0.119679 0.034234 3.496 0.000
L1.Vorarlberg 0.066122 0.030225 2.188 0.029
L1.Wien 0.095969 0.055582 1.727 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174255 0.060008 2.904 0.004
L1.Burgenland 0.005488 0.036538 0.150 0.881
L1.Kärnten -0.065956 0.019111 -3.451 0.001
L1.Niederösterreich -0.107047 0.076376 -1.402 0.161
L1.Oberösterreich 0.207214 0.075307 2.752 0.006
L1.Salzburg 0.054595 0.038759 1.409 0.159
L1.Steiermark 0.246792 0.051171 4.823 0.000
L1.Tirol 0.501773 0.041284 12.154 0.000
L1.Vorarlberg 0.064467 0.036449 1.769 0.077
L1.Wien -0.078755 0.067027 -1.175 0.240
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160466 0.066582 2.410 0.016
L1.Burgenland -0.001542 0.040542 -0.038 0.970
L1.Kärnten 0.062752 0.021205 2.959 0.003
L1.Niederösterreich 0.167801 0.084745 1.980 0.048
L1.Oberösterreich -0.056746 0.083558 -0.679 0.497
L1.Salzburg 0.208254 0.043005 4.843 0.000
L1.Steiermark 0.138956 0.056778 2.447 0.014
L1.Tirol 0.057087 0.045807 1.246 0.213
L1.Vorarlberg 0.147190 0.040442 3.640 0.000
L1.Wien 0.118762 0.074371 1.597 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390019 0.039200 9.950 0.000
L1.Burgenland -0.003775 0.023869 -0.158 0.874
L1.Kärnten -0.020870 0.012484 -1.672 0.095
L1.Niederösterreich 0.202234 0.049892 4.053 0.000
L1.Oberösterreich 0.231051 0.049194 4.697 0.000
L1.Salzburg 0.036660 0.025319 1.448 0.148
L1.Steiermark -0.015958 0.033427 -0.477 0.633
L1.Tirol 0.088914 0.026968 3.297 0.001
L1.Vorarlberg 0.051035 0.023810 2.143 0.032
L1.Wien 0.043702 0.043785 0.998 0.318
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036479 0.103914 0.168473 0.136921 0.097249 0.079461 0.032368 0.208342
Kärnten 0.036479 1.000000 -0.026624 0.130907 0.048931 0.084889 0.443781 -0.066774 0.089514
Niederösterreich 0.103914 -0.026624 1.000000 0.312185 0.119454 0.273036 0.067060 0.153734 0.292810
Oberösterreich 0.168473 0.130907 0.312185 1.000000 0.211867 0.294816 0.165700 0.136497 0.238245
Salzburg 0.136921 0.048931 0.119454 0.211867 1.000000 0.122740 0.092296 0.105094 0.124682
Steiermark 0.097249 0.084889 0.273036 0.294816 0.122740 1.000000 0.134051 0.107265 0.035860
Tirol 0.079461 0.443781 0.067060 0.165700 0.092296 0.134051 1.000000 0.064349 0.150895
Vorarlberg 0.032368 -0.066774 0.153734 0.136497 0.105094 0.107265 0.064349 1.000000 -0.004073
Wien 0.208342 0.089514 0.292810 0.238245 0.124682 0.035860 0.150895 -0.004073 1.000000